from twisted.internet import reactor, defer
from twisted.internet.protocol import ClientCreator
from twisted.protocols import amp
from ampserver import MongoQuery



def doMath():
    d1 = ClientCreator(reactor, amp.AMP).connectTCP('127.0.0.1', 1234).addCallback(lambda p: p.callRemote(MongoQuery, book_name="book write by xiong", author="xiong"))
    def done(result):
        print 'Done with math:', result
    defer.DeferredList([d1]).addCallback(done).addCallback(lambda _: reactor.stop())



if __name__ == '__main__':
    doMath()
    reactor.run()
